/*
 * DeleteLinksAction.java
 * 
 * Created by demory on Jul 13, 2008, 9:51:58 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.actions;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.fpdev.core.basenet.BLink;
import org.fpdev.core.transit.Station;
import org.fpdev.apps.rtemaster.RouteMaster;

/**
 *
 * @author demory
 */
public class DeleteLinksAction implements ACAction {

  private Set<BLink> links_;
  private Map<Integer, Station> stations_;
  
  public DeleteLinksAction(Set<BLink> links) {
    links_ = links;
    stations_ = new HashMap<Integer, Station>();
  }

  public boolean doAction(RouteMaster av) {
    stations_.clear();
    for(Iterator<BLink> links = links_.iterator(); links.hasNext();) {
      BLink link = links.next();
      av.getEngine().getBaseNet().deleteLink(link);
      if(link.isStation()) {
        stations_.put(link.getID(), link.getStation());
        link.getStation().removeLink(link);
      }
    }
    av.getEngine().getDB().deleteLinks(links_.iterator());
    return true;
  }

  public boolean undoAction(RouteMaster av) {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public String getName() {
    return "Delete Links";
  }
}
